#ifndef ACCEPTOR_H_
#define ACCEPTOR_H_

#include <ev.h>

#define HEXPRINT_LEN(x,y)	(((x)%(y)==0))
#define HEXPRINT_LINEPERCHAR 16

static inline void plugin_printhex(const unsigned char *buf, int len) {
	unsigned int i, j;
	for (i = 0; i < len; i++) {
		if (HEXPRINT_LEN(i, HEXPRINT_LINEPERCHAR)) {
			if (i != 0)
				for (j = (i - HEXPRINT_LINEPERCHAR); j < i; j++)
					if ((buf[j] > 0x20) && (buf[j] < 0x7F))
						printf("%c ", buf[j]);
					else
						printf(". ");
			printf("\n%.8X:", i);
		} else if (HEXPRINT_LEN(i, HEXPRINT_LINEPERCHAR / 2)) {
			printf("- ");
		}
			
		printf("%.2X ", buf[i]);
	}
	if (!HEXPRINT_LEN(i, HEXPRINT_LINEPERCHAR) || HEXPRINT_LEN(len, HEXPRINT_LINEPERCHAR)) {
		printf("\n");
	}
}

extern void accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents);

#endif /* ACCEPTOR_H_ */